var express = require('express');
var session = require('express-session');
var path = require('path');
var router = express.Router();
var sqlite3 = require('sqlite3').verbose();

/* GET users listing. */
router.get('/', function (req, res, next) {
  var redata = {
    count: 1,
    code: '0',
    data: []
  };
  var db = new sqlite3.Database(path.join(__dirname, "../db/data.s3db"));
  try {
    db.serialize(function () {
      sqlStr = "SELECT * from material where mid=='" + req.query.mid + "'";
      db.all(sqlStr, function (err, rows) {
        redata.data[0] = rows[0];
        redata.data[0].number = req.query.number;
        console.log(redata);
        res.send(redata);
      });
    });
  } catch (ex) {
    console.log(ex);
  }
});

module.exports = router;